﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZX_3_SchoolManage_DAL;
using System.Data.SqlClient;
using System.Data;
using ZX_3_SchoolManage_Model;

namespace ZX_3_SchoolManage_DAL
{
    public class TeachersmANAGE_DAL :ZX_3_SchoolManage_IDAL.TeacherManage_IDAL
    {
        /// <summary>
        /// 分页显示
        /// </summary>
        /// <param name="TeaName"></param>
        /// <param name="pagesize"></param>
        /// <param name="pageindex"></param>
        /// <returns></returns>
        public List<TeacherModel> getTeachershow(string TeaName, int pagesize, int pageindex)
        {
            string sql = "select * from (select row_Number() over(order by TeaId)id,Teachers.*"
                + "from Teachers where TeaName like '%" + TeaName + "')t where id between " + (pageindex - 1) * pagesize + 1 + " and " + pageindex * pagesize + "";
            return DBHelper.GetList<TeacherModel>(sql);

        }
        /// <summary>
        /// 模糊查询总条数
        /// </summary>
        /// <param name="TeaName"></param>
        /// <returns></returns>

        public int pagecount(string TeaName)
        {
            string sql = "select Count(*) from Teachers where TeaName like '%" + TeaName + "%'";
            return Convert.ToInt32(DBHelper.GetSingle(sql));
        }
        /// <summary>
        /// 添加教师信息
        /// </summary>
        /// <param name="T"></param>
        /// <returns></returns>

        public int Add(TeacherModel T)
        {
            string sql =string.Format("insert into Teachers values({0},'{1}',{2},{3},'{4}','{5}','{6}','{7}','{8}','{9}',{10},'{11}',{12})",T.TeacherID,T.TeaName,T.TeaSex,T.TeaAge,T.TeaBirthday,T.TeaAddress,T.TeaHiredate,T.TeaPolState,T.TeaPhoneNum,T.TeaState,T.TeaHasOrNoAth,T.TeaSubId,T.TeaClassId);
            return DBHelper.ExecuteSql(sql);
        }
        /// <summary>
        /// 修改教师信息
        /// </summary>
        /// <param name="Te"></param>
        /// <returns></returns>

        public int Edit(TeacherModel Te)
        {
            string sql = "update Teachers set TeacherID='" + Te.TeacherID + "',TeaName = '" + Te.TeaName + "',TeaSex = '" + Te.TeaSex + "',TeaAge = '" + Te.TeaAge + "',TeaBirthday = '" + Te.TeaBirthday + "',TeaAddress = '" + Te.TeaAddress + "',TeaHiredate='" + Te.TeaHiredate + "',TeaPolState='" + Te.TeaPolState + "',TeaHasOrNoAth='" + Te.TeaHasOrNoAth + "',TeaSubId ='" + Te.TeaSubId + "',TeaClassId='" + Te.TeaClassId + "' where TeaId='"+Te.TeaId+"'";
            return DBHelper.ExecuteSql(sql);

        }

        public int Delete(int id)
        {
            throw new NotImplementedException();
        }
    }
}
